package com.zqu.controller;

import com.zqu.pojo.Serve;
import com.zqu.pojo.User;
import com.zqu.service.ServeService;
import com.zqu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("serve")
public class ServeController {
    @Autowired
    private ServeService serveService;

    @RequestMapping("findServer")
    @ResponseBody
    public Serve findServer(){
        Serve serve = new Serve();
        serve.setId(1);
        System.out.println(serveService.findServe(serve.getId()).toString());
        return serveService.findServe(serve.getId());
    }
    @RequestMapping("findServerList")
    @ResponseBody
    public List<Serve> findServerList(){
        Serve serve = new Serve();
        serve.setServiceDistrbutionCreateUserId(1);
        System.out.println("all list"+serve+serveService);
        System.out.println(serveService.selectList(serve).toString());
        return serveService.selectList(serve);
    }
    @RequestMapping("updateServer")
    @ResponseBody
    public boolean updateServer(){
        Serve serve = new Serve();
//        serve = null;
//        serve.setId(3);
        serve.setId(1);
        serve.setServeName("谢汉锋1111111111");
        System.out.println("update ");
        boolean flag = serveService.updateT(serve);
        if(flag){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }

        return flag;
    }
    @RequestMapping("insertServer")
    @ResponseBody
    public boolean insertServer(){
        Serve serve = new Serve();
        serve.setServiceDistrbutionCreateUserId(2);
        serve.setServeName("谢汉锋");

        serve.setServeRemark("sgfdg");
        serve.setServeStandardPrice(124);
        serve.setServeType("dsdf");

        System.out.println("update ");
        boolean flag = serveService.insertT(serve);
        if(flag){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }

        return flag;
    }
    @RequestMapping("deleteServer")
    @ResponseBody
    public boolean deleteServer(){



        boolean flag = serveService.deleteT(4);
        if(flag){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }

        return flag;
    }
    @RequestMapping("deleteServerList")
    @ResponseBody
    public boolean deleteServerList(){
        String ids[] ={"5","6"};
        boolean flag = serveService.deleteTByIds(ids);
        if(flag){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }

        return flag;
    }
}
